//good 上架商品的点击事件
function addGoods(){
	window.location.href="../shoppingmall/toAddGoods.do"
}

function toUpdateGoods(sampleId){
	window.location.href="../shoppingmall/toUpdateGoods.do?sampleId="+sampleId
}

function downGoods(){
	alert("我看那看");
	
}
$("#search").click(function(){
	alert("我看看搜索");
	
	
});

$("#goodsTypeSelect").change(function(){
	if($(this).val()!=9){
		window.location.href="../shoppingmall/goodsByType.do?currentPage=1&&type="+$(this).val();
	}else{
		window.location.href="../shoppingmall/goods.do?currentPage=1";
	}
});
//商品的点击事件显示详情
function clickGoods(sampleId){
	$.post(
	"../shoppingmall/getSampleById.do?sampleId="+sampleId,
	function(data){
		
		$(".modal-body").html(makeDiv(data));
		//根据产品类型的不同, 调用不同的界面
	},
	"json"
	);
}

//点击活动,显示和修改
function clickActivity(activityId){
	$("input[name='optionsRadios']").removeProp("checked");
	$.post("../shoppingmall/getActivityById.do?activityId="+activityId,
			function(data){
				$("#activityName>div>input").val(data.activityName);
				$("#activityId").val(data.activityId);
				if(data.status==1){
					$("#openStatus").attr({checked:"checked"});
				}else{
					$("#closeStatus").attr({checked:"checked"});
				}
			
			},
			'json'
	);
}

//操作成功之后提示
function success(text){
	  $("#alerts").html("<div  style='text-align: center; display:no;' class='alert alert-success alert-dismissable'><strong>"+text+"</strong></div>");
	  $("#menus").click();
 
}

//操作失败之后提示

function fail(text){
	  $("#alerts").html("<div  style='text-align: center; display:no;' class='alert alert-success alert-dismissable'><strong>"+text+"</strong></div>");
	  $("#menus").click();

}
function myfresh(){
	window.location.href=window.location.href;
}
//保存活动
function saveActivity(){	
	$.post(
			"../shoppingmall/updateActivity.do",
			$("#activityT").serialize(),
			function(data){
				if(data==1){
					success("恭喜您, 修改成功!");
					 setTimeout(myfresh,1000);
				}else if(data==0){
					fail("对不起,修改未成功!原因:数据库异常或者你没有修改数据!!");
					setTimeout(myfresh,1000);
				}
			}
	);
}

//增加新活动
function addActivity(){
	$.post(
			"../shoppingmall/addActivity.do",
			$("#addActivity").serialize(),
			function(data){
				if(data==1){
					success("恭喜您, 活动增加成功!");
					setTimeout(myfresh,1000);
				}else if(data==0){
					fail("对不起,活动增加未成功!原因:数据库异常或者你没有修改数据!!");
				}
			}
	);
}
//删除活动
function deleteActivity(status,activityId){
	if(status==1){
		success("活动在开启状态,无法删除!");
		return;
	}
	$.post(
			"../shoppingmall/deleteActivity.do?activityId="+activityId,
			function(data){
				if(data==1){
					success("删除成功!");
					setTimeout(myfresh,1000);
				}else if(data==0){
					fail("对不起,删除未成功!原因:数据库异常或者你没有修改数据!!");
				}
			}
	);
}
//风格
//根据风格id获取风格
function toUpdatestyle(styleId){
	$.post(
			"../shoppingmall/getStyleById.do?styleId="+styleId,
			function(data){
				$("#styleName").val(data.styleContent);
				$("#styleId").val(data.styleId);
			},
			'json'
	);
}
//保存修改风格
function saveStyle(){
	$.post("../shoppingmall/updateStyle.do",
			$("#activityT").serialize(),
			function(data){
				if(data==1){
					success("恭喜您, 风格修改成功!");
					setTimeout(myfresh,1000);
				}else if(data==0){
					fail("对不起,风格修改未成功!原因:数据库异常或者你没有修改数据!!");
					setTimeout(myfresh,1000);
				}
			}	
	
	);
}
//新增风格
function addStyle(){
	$.post("../shoppingmall/addStyle.do",
			$("#addStyleII").serialize(),
			function(data){
				if(data==1){
					success("恭喜您, 风格修改成功!");
					setTimeout(myfresh,1000);
				}else if(data==0){
					fail("对不起,风格修改未成功!原因:数据库异常或者你没有修改数据!!");
				}
			}	
	);
}
//删除风格
function deleteStyle(styleId){
	$.post(
			"../shoppingmall/deleteStyle.do?styleId="+styleId,
			function(data){
				if(data==1){
					success("删除成功!");
					setTimeout(myfresh,1000);
				}else if(data==0){
					fail("对不起,由于有商品与此风格绑定,无法删除!!!");
					setTimeout(myfresh,1000);
				}
			},
			'json'
	);
}
function toUpdateLocation(locationId){
	$.post(
			"../shoppingmall/getLocationById.do?locationId="+locationId,
			function(data){
				$("#styleName").val(data.locationContent);
				$("#styleId").val(data.locationId);
			},
			'json'
	);	
}
function saveLocation(){
	$.post("../shoppingmall/saveLocation.do",
			$("#activityT").serialize(),
			function(data){
				if(data==1){
					success("恭喜您, 风格修改成功!");
					setTimeout(myfresh,1000);
				}else if(data==0){
					fail("对不起,风格修改未成功!原因:数据库异常或者你没有修改数据!!");
					setTimeout(myfresh,1000);
				}
			}	
	
	);
}
function addLocation(){
	$.post("../shoppingmall/addLocation.do",
			$("#addStyleII").serialize(),
			function(data){
				if(data==1){
					success("恭喜您, 风格修改成功!");
					setTimeout(myfresh,1000);
				}else if(data==0){
					fail("对不起,风格修改未成功!原因:数据库异常或者你没有修改数据!!");
				}
			}	
	);
}
//删除适用场景
function deleteLocation(locationId){
	$.post(
			"../shoppingmall/deleteLocation.do?locationId="+locationId,
			function(data){
				if(data==1){
					success("删除成功!");
					setTimeout(myfresh,1000);
				}else if(data==0){
					fail("对不起,由于有商品与此场景绑定,无法删除!!!");
					setTimeout(myfresh,1000);
				}
			},
			'json'
	);	
}
//一下是商品上传的js
$("button[name='addNewSeriesButton']").click(function(){
	var lLable=makeUlOfHead("addNewSeries","上架新系列产品");
	if($("#ulHead").find("a[href='#addNewSeries']").length==0){
		$("#ulHead").append(lLable);
		var modelId=$(this).parent().attr("id");
		var index=$("#ulHead").find("a[href='#"+modelId+"']").parent().index()+1;
		$('#ulHead li:eq('+index+') a').tab('show');
	}
	
});
$("button[name='addOldSeriesButton']").click(function(){
	var lLable=makeUlOfHead("addOldSeries","上架已有系列产品");
	if($("#ulHead").find("a[href='#addOldSeries']").length==0){
		$("#ulHead").append(lLable);
		var modelId=$(this).parent().attr("id");
		var index=$("#ulHead").find("a[href='#"+modelId+"']").parent().index()+1;
		$('#ulHead li:eq('+index+') a').tab('show');
	}	
	
});
$("button[name='addBuYiLianButton']").click(function(){
	var lLable=makeUlOfHead("addLianTou","布艺帘上传");
	if($("#ulHead").find("a[href='#addLianTou']").length==0){
		$("#ulHead").append(lLable);
		var modelId=$(this).parent().attr("id");
		var index=$("#ulHead").find("a[href='#"+modelId+"']").parent().index()+1;
		$('#ulHead li:eq('+index+') a').tab('show');
	}		
});
$("#buttonNext").click(function(){
	var lLable=makeUlOfHead("addZhuBu","上传主布信息");
	if($("#ulHead").find("a[href='#addZhuBu']").length==0){
		$("#ulHead").append(lLable);
		var modelId=$(this).parent().attr("id");
		var index=$("#ulHead").find("a[href='#"+modelId+"']").parent().index()+1;
		$('#ulHead li:eq('+index+') a').tab('show');
	}
	
});
$("#zhuBuButtonNext").click(function(){
	var lLable=makeUlOfHead("addPeiBu","上传配布信息");
	if($("#ulHead").find("a[href='#addPeiBu']").length==0){
		$("#ulHead").append(lLable);
		var modelId=$(this).parent().attr("id");
		var index=$("#ulHead").find("a[href='#"+modelId+"']").parent().index()+1;
		$('#ulHead li:eq('+index+') a').tab('show');

	}	
});
$("#addGoOnZhuBu").click(function(){
	var lLable=makeUlOfHead("addZhuBu","上传主布信息");
	$("#ulHead").append(lLable);
	var modelId=$(this).parent().attr("id");
	var index=$("#ulHead").find("a[href='#"+modelId+"']").parent().index()+1;
	$('#ulHead li:eq('+index+') a').tab('show');
	
});


$("#addGoOnPeiBu").click(function(){
	var lLable=makeUlOfHead("addPeiBu","上传配布信息");
	$("#ulHead").append(lLable);
	var modelId=$(this).parent().attr("id");
	var index=$("#ulHead").find("a[href='#"+modelId+"']").parent().index()+1;
	$('#ulHead li:eq('+index+') a').tab('show');
	
});
$("#peiBuButtonNext").click(function(){
	var lLable=makeUlOfHead("addPeiBu","上传配布信息");
	if($("#ulHead").find("a[href='#addPeiBu']").length==0){
		$("#ulHead").append(lLable);
		var modelId=$(this).parent().attr("id");
		var index=$("#ulHead").find("a[href='#"+modelId+"']").parent().index()+1;
		$('#ulHead li:eq('+index+') a').tab('show');

	}	
});
function makeUlOfHead(idName,stringName){
	var aLable='<a href="#'+idName+'" data-toggle="tab">'+stringName+'</a>';
	var lLable=$("<li class=''></li>");
	lLable.append(aLable);
	return lLable;
}
function makeDiv(sample){
	var jiegou;
	if(sample.structore==0){
		jiegou='单布';
	}else if(sample.structore==1){
		jiegou='单纱';
	}else{
		jiegou='布加纱';
	}
	var liantou;
	if(sample.swag==0){
		liantou='无'
	}else{
		liantou='有';
	}
	var fengmian;
	if(sample.seriesSample==1){
		fengmian='是'
	}else{
		fengmian='不是'
	}
	var kuanshi;
	if(data.isSty==0){
		kusnshi='打孔';
	}else if(data.isSty==1){
		kuanshi='韩折';
	}else{
		kuanshi='打孔,韩折';
	}
	var daDiv=$("<div style='width:560px;'>");
	daDiv.append("<div style='height:250px;width:150px;margin-top:0px;'>"+
			"<img src='http://oeilufnx2.bkt.clouddn.com/"+sample.sampleImg+"?imageView2/1/w/146/h/246'></div>"+
			"<div style='height:250px;width:410px;margin-top:-250px;margin-left:150px;'>"+
			"<div style='width:410px;height:50px;'><div style='width:100px;margin-left:10px;'>品牌: "+sample.brand+"</div><div style='margin-top:-20px;margin-left:142px;width:200px;'>"+
			"款式: "+kuanshi+"</div></div>"+
			"<div style='width:410px;height:50px;'><div style='width:100px;margin-left:10px;'>产品号: "+sample.sampleId+"</div><div style='margin-top:-20px;margin-left:142px;width:200px;'>"+
			"产品描述: "+sample.sampleDescribe+"</div></div>"+
			"<div style='width:410px;height:50px;'><div style='width:100px;margin-left:10px;'>"+"结构: "+jiegou+"</div><div style='margin-top:-20px;margin-left:142px;width:200px;'>"+
			"打孔价格: "+sample.holePrice+"</div></div>"+
			"<div style='width:410px;height:50px;'><div style='width:100px;margin-left:10px;'>"+"韩折价格: "+sample.zhePrice+"</div><div style='margin-top:-20px;margin-left:142px;width:200px;'>"+
			"单个销量: "+sample.sale+"</div></div>"+
			"<div style='width:410px;height:50px;'><div style='width:100px;margin-left:10px;'>"+"系列销量: "+sample.saleCount+"</div><div style='margin-top:-20px;margin-left:142px;width:200px;'>"+
			"类型: "+"布艺帘"+"</div></div>"+"</div>"+
			"<div style='height:300px;width:560px;margin-top:0px;'>"+
			"<div style='width:560px;height:50px;'><div style='width:100px;margin-left:10px;'>帘头: "+liantou+"</div><div style='margin-top:-20px;margin-left:142px;width:200px;'>"+
			"帘头款式: "+sample.shadeDesign+"</div>"+
			"<div style='width:100px;margin-left:252px;margin-top:-20px;'>系列号: "+sample.series+"</div><div style='margin-top:-20px;margin-left:362px;width:200px;'>"+
			"系列封面: "+fengmian+"</div></div>"+
			"<div style='width:560px;height:50px;'><div style='width:100px;margin-left:10px;'>最小宽: "+sample.minWide+"</div><div style='margin-top:-20px;margin-left:142px;width:200px;'>"+
			"最大宽: "+sample.maxWide+"</div>"+
			"<div style='width:100px;margin-left:252px;margin-top:-20px;'>最小高: "+sample.minHigh+"</div><div style='margin-top:-20px;margin-left:362px;width:200px;'>"+
			"最大高: "+sample.minHigh+"</div></div>"+
			"<div style='width:560px;height:50px;'><div style='width:100px;margin-left:10px;'>一级利润: "+sample.firstProfit+"</div><div style='margin-top:-20px;margin-left:142px;width:200px;'>"+
			"二级利润: "+sample.secondProfit+"</div>"+
			"<div style='width:100px;margin-left:252px;margin-top:-20px;'>材质: "+sample.material+"</div><div style='margin-top:-20px;margin-left:362px;width:200px;'>"+
			"计价单位: "+sample.chargeUnit+"</div></div>"+
			"<div style='width:560px;height:50px;'><div style='width:100px;margin-left:10px;'>倍折: "+sample.times_fold+"</div><div style='margin-top:-20px;margin-left:142px;width:200px;'>"+
			"折边: "+sample.hem+"</div>"+
			"<div style='width:100px;margin-left:252px;margin-top:-20px;'>遮光率: "+sample.shading+"</div><div style='margin-top:-20px;margin-left:362px;width:200px;'>"+
			"原料: "+sample.rawMaterial+"</div></div>"+
			"<div style='width:560px;height:50px;'></div>"+
			"<div style='width:560px;height:50px;'><div style='width:520px;margin-left:10px;'>洗涤说明: "+sample.isInstall+"</div></div>"
			+"</div>"
			);
	return daDiv;
}























